package com.yexiao.cofe.business.pojo;

import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.annotation.*;
import com.yexiao.core.util.JSONUtil;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.math.BigDecimal;

/**
 * 参数值
 * eg: 甜度（七分糖、正常糖）
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@TableName("param_value")
public class ParamValue {

    /**
     * 参数值ID
     */
    @TableId(type = IdType.AUTO)
    public Integer id;

    /**
     * 参数项ID
     */
    @TableField("param_item_id")
    public Integer paramItemId;

    /**
     * 参数值（如七分糖）
     */
    @TableField("value")
    public String value;

    /**
     * 价格偏移
     */
    @TableField("price_offset")
    public BigDecimal priceOffset;

    /**
     * 库存（可选）
     */
    @TableField("stock")
    public Integer stock;

    public static final String ID = "id";
    public static final String PARAM_ITEM_ID = "param_item_id";
    public static final String VALUE = "value";
    public static final String PRICE_OFFSET = "price_offset";
    public static final String STOCK = "stock";

    public static JSONObject getBaseMsg(ParamValue paramValue) {
        return JSONUtil.of(
                "id", paramValue.getId(),
                "paramItemId", paramValue.getParamItemId(),
                "value", paramValue.getValue(),
                "priceOffset", paramValue.getPriceOffset(),
                "stock", paramValue.getStock()
        );
    }
}
